package com.company.project.controller;
import com.company.project.core.Result;
import com.company.project.core.ResultGenerator;
import com.company.project.model.SysAuth;
import com.company.project.service.SysAuthService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by DLHTX on 2020/06/21.
*/
@RestController
@RequestMapping("/api/auth")
public class SysAuthController {
    @Resource
    private SysAuthService sysAuthService;

    @PostMapping("/addAuth")
    public Result addAuth(@RequestBody SysAuth sysAuth) {
        sysAuthService.save(sysAuth);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    public Result delete(@RequestParam Integer id) {
        sysAuthService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/editAuth")
    public Result editAuth(@RequestBody SysAuth sysAuth) {
        sysAuthService.update(sysAuth);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        SysAuth sysAuth = sysAuthService.findById(id);
        return ResultGenerator.genSuccessResult(sysAuth);
    }

    @PostMapping("/getAuth")
    public Result getAuth(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "100") Integer size) {
        PageHelper.startPage(page, size);
        List<SysAuth> list = sysAuthService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
}
